﻿#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
from lib.parsing import *
import json

INDEX_NAME = "recipes_index"

def parse_all_gotovim_doma_recipes():
  DATA_DIR = os.path.join(os.getcwd(), "data/gotovim_doma")
  RESULT_FILE = os.path.join(os.getcwd(), "data/gotovim_doma.json")
  IMAGES_FILE = os.path.join(os.getcwd(), "data/gotovim_doma_images.txt")

  outfile = open(RESULT_FILE, 'w')
  imgfile = open(IMAGES_FILE, 'w')

  index = 0
  for file in os.listdir(DATA_DIR):
    f = open(os.path.join(DATA_DIR, file))
  
    parser = gotovim_doma.GotovimDomaParser()
    for line in f:
      parser.feed(line.strip().decode('cp1251'))
    recipe = parser.get_parsed_recipe()
    
    outfile.write(recipe.as_json() + "\n")
    imgfile.write(recipe.main_photo + "\n")
    index += 1
    print index

parse_all_gotovim_doma_recipes()